package com.ursu.client;

import com.google.gwt.event.shared.EventBus;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.proxy.Gatekeeper;
import com.ursu.client.event.LoginAuthenticatedEvent;
import com.ursu.client.event.LoginAuthenticatedEvent.LoginAuthenticatedHandler;
import com.ursu.client.model.CurrentUser;

public class LoggedInGatekeeper implements Gatekeeper , LoginAuthenticatedHandler {
	
	private  CurrentUser currentUser;
	private EventBus eventBus;
	
	@Inject
	public LoggedInGatekeeper(final EventBus eventBus){
		this.eventBus = eventBus;
		this.eventBus.addHandler(LoginAuthenticatedEvent.getType(), this);
	}

	@Override
	public boolean canReveal() {
		boolean loggedIn = false;
		
		if(currentUser != null ){
		loggedIn = currentUser.isLoggedIn();
		}
		return loggedIn;
	}


	@Override
	public void onLoginAuthenticated(LoginAuthenticatedEvent event) {
		currentUser = event.getCurrentUser();
		
	}

}
